﻿@model MessageIndexModel
@{
    var x = Html.X();
}

<script>
    function treeclick(view, record, item, index, e) {
        var store = Ext.getCmp("MassageGrid").getStore();

        if (record.raw.text === "收件箱") {
            store.proxy.url = "@Url.Action("GetPaged")";
        }
        else if (record.raw.text === "发件箱") {
            store.proxy.url = "@Url.Action("GetOutboxPaged")";
        }
        else if (record.raw.text === "草稿箱") {
            store.proxy.url = "@Url.Action("GetDraftboxPaged")";
        }
        else if (record.raw.text === "回收站") {
            store.proxy.url = "@Url.Action("GetDustbinPaged")";
        }
        store.proxy.extraParams = { type: record.raw.type };
        store.load();
    }
    function treeSelectedValue() {
        var selected = Ext.getCmp("treeMassage").getSelectionModel().getSelection();
        if (selected.length === 0) {
            return "";
        }
        return selected[0].raw.type;
    }
</script>

@(
    x.Panel().Layout(LayoutType.Border).Items(
        x.TreePanel().ID("treeMassage")
                .Title("消息管理")
                .Region(Region.West)
                .Layout(LayoutType.Fit)
                .Width(225)
                .MinWidth(225)
                .MaxWidth(400)
                .Split(true)
                .Collapsible(false).TopBar(
                            x.Toolbar().Items(x.Button().Text("发送消息").OnClientClick("App.Grid.OnModuleOperation(this,'" + Url.Action("Send") + "',{ShowOnly:true,type:treeSelectedValue()});")))
            .RootVisible(false).HideHeaders(true).Animate(false).Root(Model.LeftTree).Lines(false)
            .Listeners(l => l.ItemClick.Fn = "treeclick"),
           x.GridPanel().ID("MassageGrid").Region(Region.Center).Layout(LayoutType.Fit)
               .Split(true)
                    .TopBar(x.Toolbar().Items(
                            x.Button().Text("浏览").OnClientClick("App.Grid.OnModuleOperation(this,'" + Url.Action("Details") + "',{type:treeSelectedValue()});"),

                        x.Button().Text("删除").OnClientClick("App.Grid.OnModuleOperation(this,'" + Url.Action("Delete") + "',{IsAjax:true,type:treeSelectedValue()});")
                        ,
                        new ToolbarFill(),
                        x.TextField().Width(300).FieldLabel("搜索").LabelWidth(50)
                            .Triggers(
                                x.FieldTrigger().Icon(TriggerIcon.Clear).HideTrigger(true),
                                x.FieldTrigger().Icon(TriggerIcon.Search)
                            )
                                .Listeners(ls => { ls.TriggerClick.Fn = "App.Main.searchFieldTriggerClick"; })
                        ))
                        .Store(x.StoreForModel().AutoLoad(true)
                            .Proxy(x.AjaxProxy().Url(Url.Action("GetPaged")).Reader(x.JsonReader().RootProperty("data")).ActionMethods(am => am.Read = HttpMethod.POST))
                            .RemoteSort(true).RemotePaging(true).PageSize(25)
                        .SorterFor(Model, m => m.Id, Ext.Net.SortDirection.DESC))
                    .SelectionModel(x.CheckboxSelectionModel())
                    .ColumnModel(
                        x.ColumnFor(m => m.SenderName),
                        x.ColumnFor(m => m.Content),
                        x.ColumnFor(m => m.PublishTime)
                    )
                    .BottomBar(x.PagingToolbar().ItemsFromPartial("~/Views/Shared/_PagingToolbarPartial.cshtml"))
                    .EmptyText("无数据。")
                    .View(Html.X().GridView().StripeRows(true).TrackOver(true))
                        .Listeners(li =>
                        {
                            li.ItemDblClick.Fn = "App.Grid.OnModuleGridItemDblClick";
                            li.ColumnHide.Fn = "App.Grid.HideColumn";
                            li.ColumnResize.Fn = "App.Grid.ResizeColumn";
                            li.ColumnMove.Fn = "App.Grid.MoveColumn";
                            li.ColumnShow.Fn = "App.Grid.ShowColumn";
                        })
                        .SharpReconfigure(Model)
            )

)